//
//  ProductTechnicalDetailViewController.m
//  AmazingShopping
//
//  Created by Tan on 5/6/13.
//  Copyright (c) 2013 Tan Hoang. All rights reserved.
//

#import "ProductTechnicalDetailViewController.h"
#import "TechnicalAndFeatureCell.h"
#import "ProductInfoCell.h"

@interface ProductTechnicalDetailViewController ()

@end

@implementation ProductTechnicalDetailViewController

@synthesize productDetails;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = @"Features & Technicals";
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

#pragma mark Table View Data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    int row = [indexPath row];
    
    if (row == 0) {
        //Init cell
        static NSString *ProductInfoIndentifier = @"ProductInfoIndentifier";
        UINib *nib = [UINib nibWithNibName:@"ProductInfoCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:ProductInfoIndentifier];
        ProductInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:ProductInfoIndentifier];
        
        //Set cell data
        [cell setProductName: [[productDetails objectAtIndex:0] valueForKey:@"product_name"]];
        [cell setPrice: [[productDetails objectAtIndex:0] valueForKey:@"product_price"]];
        [cell setSellerName:[[productDetails objectAtIndex:0] valueForKey:@"seller_name"]];
        
        return cell;
    }else{
        //Init cell
        static NSString *TechnicalAndFeatureIdentifier = @"TechnicalAndFeatureIdentifier";
        UINib *nib = [UINib nibWithNibName:@"TechnicalAndFeatureCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:TechnicalAndFeatureIdentifier];
        TechnicalAndFeatureCell *cell = [tableView dequeueReusableCellWithIdentifier:TechnicalAndFeatureIdentifier];
        
        //Set cell data
        if (row == 1) {
            [cell setTitle:@"Product Features"];
            [cell setDetailText:[[productDetails objectAtIndex:0] valueForKey:@"product_feature"]];
        }
        if (row == 2) {
            [cell setTitle:@"Product Technicals"];
            [cell setDetailText:[[productDetails objectAtIndex:0] valueForKey:@"product_technical"]];
        }
        
//        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        
        return cell;
    }
}

@end
